﻿<!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
-->

<UserControl x:Class="System.Windows.Controls.Samples.TimePickerArabicCulture"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:inputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit" 
    xmlns:samples="clr-namespace:System.Windows.Controls.Samples">
  
  <StackPanel Background="White">
    <ContentControl Content="List picker (ar-EG)" Style="{StaticResource Header}" />
    <inputToolkit:TimePicker Width="150" Culture="ar-EG">
      <inputToolkit:TimePicker.TimeGlobalizationInfo>
        <samples:ArabicTimeGlobalizationInfo />
      </inputToolkit:TimePicker.TimeGlobalizationInfo>
    </inputToolkit:TimePicker>

    <ContentControl Content="Range picker (ar-EG)" Style="{StaticResource Header}" />
    <inputToolkit:TimePicker Width="150" Culture="ar-EG">
      <inputToolkit:TimePicker.TimeGlobalizationInfo>
        <samples:ArabicTimeGlobalizationInfo />
      </inputToolkit:TimePicker.TimeGlobalizationInfo>
      <inputToolkit:TimePicker.Popup>
        <inputToolkit:RangeTimePickerPopup />
      </inputToolkit:TimePicker.Popup>
    </inputToolkit:TimePicker>
  
    <ContentControl Content="TimeUpDown (ar-EG)" Style="{StaticResource Header}" />
    <inputToolkit:TimeUpDown Width="150" Culture="ar-EG">
      <inputToolkit:TimeUpDown.TimeGlobalizationInfo>
        <samples:ArabicTimeGlobalizationInfo />
      </inputToolkit:TimeUpDown.TimeGlobalizationInfo>
    </inputToolkit:TimeUpDown>

    <src:SourceViewer xmlns:src="clr-namespace:System.Windows.Controls.Samples;assembly=System.Windows.Controls.Samples.Common" xmlns:sys="clr-namespace:System;assembly=mscorlib">
  <src:SourceFile Path="ArabicTimeGlobalizationInfo.cs">
    <src:SourceFile.Source>
      <sys:String>// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System.Collections.Generic;
using System.Globalization;

namespace System.Windows.Controls.Samples
{
    /// &lt;summary&gt;
    /// Overridden TimeGlobalizationInfo for shows mapping of characters to 
    /// Arabic.
    /// &lt;/summary&gt;
    public class ArabicTimeGlobalizationInfo : TimeGlobalizationInfo
    {
        /// &lt;summary&gt;
        /// Dictionary helpful for translation.
        /// &lt;/summary&gt;
        private readonly Dictionary&lt;int, char&gt; arabicNumbers = new Dictionary&lt;int, char&gt;
                                                                    {
                                                                            { 0, '٠' },
                                                                            { 1, '١' },
                                                                            { 2, '٢' },
                                                                            { 3, '٣' },
                                                                            { 4, '٤' },
                                                                            { 5, '٥' },
                                                                            { 6, '٦' },
                                                                            { 7, '٧' },
                                                                            { 8, '٨' },
                                                                            { 9, '٩' }
                                                                    };

        /// &lt;summary&gt;
        /// Returns the global representation of a character.
        /// &lt;/summary&gt;
        /// &lt;param name="input"&gt;Character that will be mapped to a different
        /// character.&lt;/param&gt;
        /// &lt;returns&gt;
        /// The global version of a character that represents the input.
        /// &lt;/returns&gt;
        protected override char MapDigitToCharacter(int input)
        {
            if (arabicNumbers.ContainsKey(input))
            {
                return arabicNumbers[input];
            }
            else
            {
                return base.MapDigitToCharacter(input);
            }
        }

        /// &lt;summary&gt;
        /// Returns the char that is represented by a global character.
        /// &lt;/summary&gt;
        /// &lt;param name="input"&gt;The global version of the character that needs
        /// to be mapped to a regular character.&lt;/param&gt;
        /// &lt;returns&gt;
        /// The character that represents the global version of a character.
        /// &lt;/returns&gt;
        protected override char MapCharacterToDigit(char input)
        {
            if (arabicNumbers.ContainsValue(input))
            {
                foreach (var pair in arabicNumbers)
                {
                    if (pair.Value == input)
                    {
                        return pair.Key.ToString(CultureInfo.InvariantCulture)[0];
                    }
                }
            }

            return base.MapCharacterToDigit(input);
        }
    }
}</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="ArabicTimeGlobalizationInfo.vb">
    <src:SourceFile.Source>
      <sys:String>' (c) Copyright Microsoft Corporation.
' This source is subject to the Microsoft Public License (Ms-PL).
' Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
' All other rights reserved.

Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Globalization

''' &lt;summary&gt;
''' Overridden TimeGlobalizationInfo for shows mapping of characters to 
''' Arabic.
''' &lt;/summary&gt;
Public Class ArabicTimeGlobalizationInfo
    Inherits TimeGlobalizationInfo
    ''' &lt;summary&gt;
    ''' Dictionary helpful for translation.
    ''' &lt;/summary&gt;
    Private ReadOnly arabicNumbers As New Dictionary(Of Integer, Char)

    ''' &lt;summary&gt;
    ''' Initializes a new instance of the ArabicTimeGlobalizationInfo class.
    ''' &lt;/summary&gt;
    Public Sub New()
        arabicNumbers.Add(0, "٠"c)
        arabicNumbers.Add(1, "١"c)
        arabicNumbers.Add(2, "٢"c)
        arabicNumbers.Add(3, "٣"c)
        arabicNumbers.Add(4, "٤"c)
        arabicNumbers.Add(5, "٥"c)
        arabicNumbers.Add(6, "٦"c)
        arabicNumbers.Add(7, "٧"c)
        arabicNumbers.Add(8, "٨"c)
        arabicNumbers.Add(9, "٩"c)
    End Sub

    ''' &lt;summary&gt;
    ''' Returns the global representation of a character.
    ''' &lt;/summary&gt;
    ''' &lt;param name="input"&gt;Character that will be mapped to a different
    ''' character.&lt;/param&gt;
    ''' &lt;returns&gt;
    ''' The global version of a character that represents the input.
    ''' &lt;/returns&gt;
    Protected Overrides Function MapDigitToCharacter(ByVal input As Integer) As Char
        If arabicNumbers.ContainsKey(input) Then
            Return arabicNumbers(input)
        Else
            Return MyBase.MapDigitToCharacter(input)
        End If
    End Function

    ''' &lt;summary&gt;
    ''' Returns the char that is represented by a global character.
    ''' &lt;/summary&gt;
    ''' &lt;param name="input"&gt;The global version of the character that needs
    ''' to be mapped to a regular character.&lt;/param&gt;
    ''' &lt;returns&gt;
    ''' The character that represents the global version of a character.
    ''' &lt;/returns&gt;
    Protected Overrides Function MapCharacterToDigit(ByVal input As Char) As Char
        If arabicNumbers.ContainsValue(input) Then
            For Each pair In arabicNumbers
                If pair.Value = input Then
                    Return pair.Key.ToString(CultureInfo.InvariantCulture)(0)
                End If
            Next pair
        End If

        Return MyBase.MapCharacterToDigit(input)
    End Function
End Class
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="TimePickerArabicCulture.xaml">
    <src:SourceFile.Source>
      <sys:String>&lt;!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
--&gt;

&lt;UserControl x:Class="System.Windows.Controls.Samples.TimePickerArabicCulture"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:inputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit" 
    xmlns:samples="clr-namespace:System.Windows.Controls.Samples"&gt;
  
  &lt;StackPanel Background="White"&gt;
    &lt;ContentControl Content="List picker (ar-EG)" Style="{StaticResource Header}" /&gt;
    &lt;inputToolkit:TimePicker Width="150" Culture="ar-EG"&gt;
      &lt;inputToolkit:TimePicker.TimeGlobalizationInfo&gt;
        &lt;samples:ArabicTimeGlobalizationInfo /&gt;
      &lt;/inputToolkit:TimePicker.TimeGlobalizationInfo&gt;
    &lt;/inputToolkit:TimePicker&gt;

    &lt;ContentControl Content="Range picker (ar-EG)" Style="{StaticResource Header}" /&gt;
    &lt;inputToolkit:TimePicker Width="150" Culture="ar-EG"&gt;
      &lt;inputToolkit:TimePicker.TimeGlobalizationInfo&gt;
        &lt;samples:ArabicTimeGlobalizationInfo /&gt;
      &lt;/inputToolkit:TimePicker.TimeGlobalizationInfo&gt;
      &lt;inputToolkit:TimePicker.Popup&gt;
        &lt;inputToolkit:RangeTimePickerPopup /&gt;
      &lt;/inputToolkit:TimePicker.Popup&gt;
    &lt;/inputToolkit:TimePicker&gt;
  
    &lt;ContentControl Content="TimeUpDown (ar-EG)" Style="{StaticResource Header}" /&gt;
    &lt;inputToolkit:TimeUpDown Width="150" Culture="ar-EG"&gt;
      &lt;inputToolkit:TimeUpDown.TimeGlobalizationInfo&gt;
        &lt;samples:ArabicTimeGlobalizationInfo /&gt;
      &lt;/inputToolkit:TimeUpDown.TimeGlobalizationInfo&gt;
    &lt;/inputToolkit:TimeUpDown&gt;
  &lt;/StackPanel&gt;
&lt;/UserControl&gt;
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="TimePickerArabicCulture.xaml.cs">
    <src:SourceFile.Source>
      <sys:String>// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System.ComponentModel;

namespace System.Windows.Controls.Samples
{
    /// &lt;summary&gt;
    /// Sample for Arabic culture.
    /// &lt;/summary&gt;
    [Sample("With Arabic Globalization", DifficultyLevel.Basic)]
    [Category("TimePicker")]
    public partial class TimePickerArabicCulture : UserControl
    {
        /// &lt;summary&gt;
        /// Initializes a new instance of the &lt;see cref="TimePickerArabicCulture"/&gt; class.
        /// &lt;/summary&gt;
        public TimePickerArabicCulture()
        {
            InitializeComponent();
        }
    }
}
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="TimePickerArabicCulture.xaml.vb">
    <src:SourceFile.Source>
      <sys:String>' (c) Copyright Microsoft Corporation.
' This source is subject to the Microsoft Public License (Ms-PL).
' Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
' All other rights reserved.

Imports Microsoft.VisualBasic
Imports System.ComponentModel

''' &lt;summary&gt;
''' Sample for Arabic culture.
''' &lt;/summary&gt;
&lt;Sample("With Arabic Globalization", DifficultyLevel.Basic), Category("TimePicker")&gt; _
Partial Public Class TimePickerArabicCulture
    Inherits UserControl
    ''' &lt;summary&gt;
    ''' Initializes a new instance of the &lt;see cref="TimePickerArabicCulture"/&gt; class.
    ''' &lt;/summary&gt;
    Public Sub New()
        InitializeComponent()
    End Sub
End Class
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
</src:SourceViewer>
  </StackPanel>
</UserControl>
